﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Data.SqlClient;
using saveimagetodatabase;
using System.IO;


namespace WcfServiceLibrary2
{
    [DataContract]
   public class ImageData
    {
        
        public string path{get;set;}
        public MemoryStream image{get;set;}
        public static ImageData GetImage(string path)
        {
           try
           {
               SqlQuery sql = new SqlQuery();

               ImageData ima = new ImageData();
              byte[]data= sql.GetImage(path);
              ima.image = new MemoryStream(data);
              ima.image.Seek(0, SeekOrigin.Begin);
               ima.path = string.Empty;
               return ima;
           }
           catch (System.Exception ex)
           {
               
               throw;
           }
        }
        public static byte[] SendImage(byte[]data)
        {
            return data
                ;
        }
        public static List<ImageData>GetImagePath()
        {
            try
            {
                SqlQuery sql = new SqlQuery();
                List<string> list = sql.GetAllPath();
                List<ImageData> imagedata = new List<ImageData>();
                foreach (string path in list)
                {
                    ImageData image = new ImageData();
                    image.image = null;
                    image.path = path;
                    imagedata.Add(image);
                }
                return imagedata;
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
    }
}
